home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / cbibcode.arc / STVSLPG.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-05  |  998 b   |  32 lines

  1. #include <stdlib.h>
  2. #include <graphics.h>
  3.  
  4. main()
  5. {
  6.    int graphdriver = DETECT, graphmode, x1, x2, y1, y2, maxx, maxy, maxcolor;
  7. /* Detect adapter type and initialize graphics system */
  8.    initgraph(&graphdriver, &graphmode, "c:\\turboc");
  9.    outtextxy(10,10, "animating a line using 'setwritemode'");
  10.    maxx = getmaxx()-100;
  11.    maxy = getmaxy()-60;
  12.    maxcolor = getmaxcolor();
  13.    randomize(); /* Initialize random number generator */
  14. /* Exit when user presses a key */
  15.    outtextxy(10, getmaxy()-30, " Press any key to exit");
  16.    while (!kbhit())
  17.    {
  18. /* Generate random end points for the lines */
  19.       x1 = random(maxx) + 50;
  20.       x2 = random(maxx) + 50;
  21.       y1 = random(maxy) + 30;
  22.       y2 = random(maxy) + 30;
  23.       setcolor(random(maxcolor));
  24. /* Now draw the line */
  25.       setwritemode(COPY_PUT);
  26.       line(x1,y1, x2,y2);
  27. /* and erase it by redrawing it in XOR_PUT mode */
  28.       setwritemode(XOR_PUT);
  29.       line(x1,y1, x2,y2);
  30.    }
  31.    closegraph();
  32. }